<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <style>
        html, body {
            background-color: #f8f8f8;
        }
        .main {
            padding: 10px;
            padding-top: 0;
        }
        .main ul {
            overflow: hidden;
        }
        .main ul li {
            width: 50%;
            float: left;
            box-sizing: border-box;
            margin-top: 10px;
            padding: 0 5px 0 0;
        }
        .main ul li:nth-child(2n) {
            padding: 0 0 0 5px;
        }
        .main .box {
            width: 100%;
        	background-color: #fff;
        }
        .main .box .box_t {
            width: 100%;
            height: 0;
            padding-top: 100%;
            position: relative;
        }
        .main .box .box_t .img_box {
            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
        }
        .main .box .box_t .img_box img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        .main .box .box_t .shop_name {
            width: 100%;
            position: absolute;
            bottom: 0;
            background-color: rgba(0, 0, 0, 0.5);
            color: #fff;
            font-size: 12px;
            box-sizing: border-box;
            padding: 3px 0 3px 3px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .main .box .box_t .shop_name img {
            height: 12px;
        }
        .main .box .box_t .shop_name span {
            display: inline;
        }
        .main .box .box_b {
            padding: 10px 5px;
            position: relative;
        }
        .main .box .box_b .title {
            color: #000;
            font-weight: bold;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            height: 22px;
            line-height: 22px;
        }
        .main .box .box_b .price {
            color: #fb0201;
            font-size: 12px;
            font-weight: bold;
            margin-top: 5px;
        }
        .main .box .box_b .btn {
            width: 40px;
            height: 20px;
            line-height: 20px;
            padding: 2px 5px;
            color: #fff;
            font-size: 12px;
            font-weight: bold;
            background-color: #fb0201;
            border-radius: 5px;
            text-align: center;
            position: absolute;
            right: 5px;
            bottom: 5px;
        }
        .loading{
            color: #ccc;
            text-align: center;
            line-height: 25px;
            display: none;
            background: #f8f8f8;
        }
        .without_data{
            text-align: center;
            display: none;
            background: #f8f8f8;
            color: #999;
            line-height: 30px;
        }
        .hidden_img{
            display: none;
        }
    </style>
</head>
<body>
    <div class="main">
        <ul id="shopC">
            <!-- <li>
                <div class="box">
                    <div class="box_t">
                        <div class="img_box">
                            <img src="../image/temp/1.png">
                        </div>
                        <div class="shop_name">
                            <img src="../image/cart.png">
                            <span>这里显示商家名称</span>
                        </div>
                    </div>
                    <div class="box_b">
                        <div class="title">秘制三杯鸡</div>
                        <div class="price">RM<span>12.50</span></div>
                        <div class="btn">订餐</div>
                    </div>
                </div>
            </li>
            <li>
                <div class="box">
                    <div class="box_t">
                        <div class="img_box">
                            <img src="../image/temp/1.png">
                        </div>
                        <div class="shop_name">
                            <img src="../image/cart.png">
                            <span>这里显示商家名称这里显示商家名称这里显示商家名称</span>
                        </div>
                    </div>
                    <div class="box_b">
                        <div class="title">秘制三杯鸡秘制三杯鸡秘制三杯鸡</div>
                        <div class="price">RM<span>12.50</span></div>
                        <div class="btn">订餐</div>
                    </div>
                </div>
            </li>
            <li>
                <div class="box">
                    <div class="box_t">
                        <div class="img_box">
                            <img src="../image/temp/1.png">
                        </div>
                        <div class="shop_name">
                            <img src="../image/cart.png">
                            <span>ab</span>
                        </div>
                    </div>
                    <div class="box_b">
                        <div class="title">121</div>
                        <div class="price">RM<span>12.50</span></div>
                        <div class="btn">订餐</div>
                    </div>
                </div>
            </li> -->
        </ul>
        <div class="without_data">暂无数据</div>
        <div class="loading">loading...</div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script id="shopL" type="text/x-dot-template">
{{ for(var i=0;i<it.length;i++){ }}
    <li>
        <div class="box">
            <div class="box_t" onclick="fnOpenSeller({{=it[i]['shop_id']}});" tapmode>
                <div class="img_box">
                    <img src="../image/default.png">
                    <img onload="setImg(this);" class="hidden_img" src="{{=formatVideoImg(it[i]['goods_img'])}}">
                </div>
                <div class="shop_name">
                    <img src="../image/cart.png">
                    <span>{{=it[i]['name']}}</span>
                </div>
            </div>
            <div class="box_b">
                <div class="title">{{=it[i]['goods_name']}}</div>
                <div class="price">RM<span>{{=it[i]['price']}}</span></div>
                <div class="btn" tapmode data-id="{{=it[i]['shop_id']}}" onclick="fnToOrder('{{=it[i]['id']}}','{{=it[i]['price']}}',this);">订餐</div>
            </div>
        </div>
    </li>
{{ }; }}
</script>
<script type="text/javascript">

    var p = 1; 
    var canLoad = false; // 默认不能上拉加载更多...
    
    apiready = function(){
        fnGetSaleGoodsShop();

        //上拉加载
        api.addEventListener({
            name:'scrolltobottom',
            extra:{
                threshold:0            //设置距离底部多少距离时触发，默认值为0，数字类型
            }
        }, function(ret, err){
            if(canLoad) {
                canLoad = false;
                p++;
                fnGetSaleGoodsShop(2);
                
            }
        });

        //下拉刷新
        api.setCustomRefreshHeaderInfo({
            bgColor: '#f8f8f8',
            loadAnimInterval:60,
            image: {
               pull: pullArr,
               load: loadArr
            }
        }, function(ret, err) {
            p = 1;
            canLoad = false;
            fnGetSaleGoodsShop(1);
        });

    };

    function fnToOrder (_id,_price,_this) {
        var _shop_id = $(_this).attr('data-id');
        fnOpenSeller(_shop_id,_id,_price);
        /*var thisid = '#goods'+_id;
        var system = api.systemType;
        if(system == 'ios'){
            setTimeout(function(){
                api.execScript({
                    name: 'seller',
                    frameName: 'seller_goods_frame',
                    script: 'fnAdd("'+thisid+'","'+_id+'","'+_price+'");'
                });
            },800);
        }else{
            setTimeout(function(){
                api.execScript({
                    name: 'seller',
                    frameName: 'seller_goods_frame',
                    script: 'fnAdd("'+thisid+'","'+_id+'","'+_price+'");'
                });
            },1000);
        }*/
    };

    function fnOpenSeller(_shop_id,_goods_id,_price) {
        api.openWin({
            name: 'seller',
            url: './seller.html',
            pageParam: {
                id: _shop_id,
                goods_id : _goods_id,
                price : _price
            }
        });
    }


    function fnGetSaleGoodsShop (_t) {
        if(_t == 2){
            $(".loading").show();
        }
        openLoading();
        var user = $api.getStorage('user_data');
        var lat = $api.getStorage('now_lat',lat);
        var lng = $api.getStorage('now_lng',lng);
        api.ajax({
            url: rootPath+'/api/shop/get_sale_goods_shops',
            method: 'get',
            data: {
                values: { 
                    p:p,
                    page_num:10,
                    lat:lat,
                    lng:lng
                },
            }
        }, function(ret, err) {
            if (ret && ret.status == 200) {
                $(".without_data").hide();
                if(_t == 2){
                    appendDotData(ret.data,'shopL','shopC',true);
                }else{
                    setDotData(ret.data,'shopL','shopC',true);
                }
                if(ret.data.length == 10){
                    canLoad = true;
                }
            }else{
                $(".without_data").show();
            }
            if(_t == 1) {
                // 是下拉刷新的，要收回
                api.refreshHeaderLoadDone();
            }
            $(".loading").hide();
            closeLoading();
        });
    };



</script>
</html>